﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Mimoza.GUI;

namespace Mimoza.SystemPlugin
{
    public partial class ShortcutsPage : UserControl, Mimoza.GUI.IWizardPage
    {
        public ShortcutsPage()
        {
            InitializeComponent();
        }

        SystemPluginData m_data;

        #region IWizardPage Members
        private IWizard m_wizard;

        private bool m_IsConfigured = true;

        public void Init(Mimoza.GUI.IWizard wizard)
        {
            m_wizard = wizard;
            m_data = this.Wizard.UserData as SystemPluginData;

            this.cbMyDevice.Checked = (m_data.ShownShortcutBitMask & ShortcutBitmask.MyComputer) != 0;
            this.cbRecycleBin.Checked = (m_data.ShownShortcutBitMask & ShortcutBitmask.RecycleBin) != 0;
            this.cbInternetExplorer.Checked = (m_data.ShownShortcutBitMask & ShortcutBitmask.InternetExplorer) != 0;
            this.cbDefaultRDP.Checked = (m_data.ShownShortcutBitMask & ShortcutBitmask.DefaultRDP) != 0;

            this.cbMyDevice.CheckStateChanged += new System.EventHandler(this.cbMyDevice_CheckStateChanged);
            this.cbRecycleBin.CheckStateChanged += new System.EventHandler(this.cbMyDevice_CheckStateChanged);
            this.cbInternetExplorer.CheckStateChanged += new System.EventHandler(this.cbMyDevice_CheckStateChanged);
            this.cbDefaultRDP.CheckStateChanged += new System.EventHandler(this.cbMyDevice_CheckStateChanged);
        }

        public void EnterPage()
        {
        }

        public bool Try2LeavePage(WizardPageLeavingDirection direction)
        {
            if (direction == WizardPageLeavingDirection.Back)
            {
                return true;
            }

            m_data.ShownShortcutBitMask = ShortcutBitmask.None;
            if (this.cbMyDevice.Checked)
            {
                m_data.ShownShortcutBitMask = m_data.ShownShortcutBitMask | ShortcutBitmask.MyComputer;
            }

            if (this.cbRecycleBin.Checked)
            {
                m_data.ShownShortcutBitMask = m_data.ShownShortcutBitMask | ShortcutBitmask.RecycleBin;
            }

            if (this.cbInternetExplorer.Checked)
            {
                m_data.ShownShortcutBitMask = m_data.ShownShortcutBitMask | ShortcutBitmask.InternetExplorer;
            }

            if (this.cbDefaultRDP.Checked)
            {
                m_data.ShownShortcutBitMask = m_data.ShownShortcutBitMask | ShortcutBitmask.DefaultRDP;
            }

            return true;
        }

        public Mimoza.GUI.IWizard Wizard
        {
            get
            {
                return m_wizard;
            }
        }

        public string PageName
        {
            get { return Resource.ShortcutPageName; }
        }

        public string PageTitle
        {
            get { return Resource.ShortcutPageNameTitle; }
        }

        public bool IsConfigured
        {
            get
            {
                return m_IsConfigured;
            }
            set
            {
                m_IsConfigured = value;
            }
        }

        public event Mimoza.GUI.PageEvent OnPageModified;

        #endregion
        protected void RaiseOnPageModified()
        {
            PageEvent handler = OnPageModified;

            if (handler != null)
            {
                handler(this);
            }
        }

        private void cbMyDevice_CheckStateChanged(object sender, EventArgs e)
        {
            this.RaiseOnPageModified();
        }
    }
}
